import React, { Component } from 'react';
import { TextareaItem,InputItem,Button,WhiteSpace,NavBar} from 'antd-mobile';
import { connect } from 'react-redux'
import {Redirect} from 'react-router-dom'
import AvatarSelector from '../../component/avatar-selector/avatar-selector'
import { update } from '../../redux/user.redux.js'
class Bossinfo extends Component {
  constructor(props) {
    super(props);
    this.state={
        title:'',
        company:'',
        money:'',
        desc:''
    }
    this.selectAvatar = this.selectAvatar.bind(this)
  }

  handleChange(type,value){
    this.setState({
        [type]:value
    })
  }

  selectAvatar(imgname){
    this.setState({
        avatar:imgname
    })
  }

  render() {
    const path = this.props.location.pathname
    const redirect = this.props.redirectTo
    return (
      <div className="Bossinfo">
      {redirect&&redirect!==path?<Redirect to={this.props.redirectTo}></Redirect>:null}
        <NavBar mode="dark">BOSS完善信息页</NavBar>
        <AvatarSelector selectAvatar={this.selectAvatar}></AvatarSelector>

            <InputItem onChange={v=>this.handleChange('title',v)}>招聘职位</InputItem>
            <WhiteSpace/>
            <InputItem onChange={v=>this.handleChange('company',v)}>公司名称</InputItem>
            <WhiteSpace/> 
            <InputItem onChange={v=>this.handleChange('money',v)}>职位薪资</InputItem>
            <WhiteSpace/> 
            <TextareaItem
            onChange={v=>this.handleChange('desc',v)}
            title="职位要求"
            rows={3}
            autoHeight
            > </TextareaItem>
            <WhiteSpace/> 
            <Button type='primary' onClick={()=>{
                this.props.update(this.state)
            }}>保存</Button>
      </div>
    );
  }
}
const mapStatetoProps =(state)=>{
  return state.user
}

const actionCreators = {update}
Bossinfo = connect(mapStatetoProps,actionCreators)(Bossinfo)
export default Bossinfo;

